﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using System.Collections.Generic;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UserInfo user = Yipusoft.Account.BLL.User.GetUser(Context.User.Identity.Name);
            UserName.Text = user.UserName + " [" + Department.GetDepartment(user.DepartmentID).FullName + "]";
            BindNavMenu();

        }
    }
    private void BindNavMenu()
    {
        NavMenu.InnerHtml = "";
        List<MenuInfo> userMenus = Yipusoft.Account.BLL.User.GetMenuList(Context.User.Identity.Name);
        userMenus = userMenus.FindAll(delegate(MenuInfo m)
        {
            if (m.ParentID == "")
                return true;
            else
                return false;
        });
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("<ul>");
        foreach (MenuInfo menu in userMenus)
        {
            sb.AppendLine("<li><a href=\"" + menu.MenuUrl + "?RootMenuID=" + menu.MenuID + "\" target=\"mainFrame\"><span class=\"title\">" + menu.MenuName + "</span></a></li>");
        }
        sb.AppendLine("</ul>");
        NavMenu.InnerHtml = sb.ToString();
    }
    public string CheckUser()
    {
        string ReturnPage = "";
        UserInfo user = Yipusoft.Account.BLL.User.GetUser(Context.User.Identity.Name);

        if (user.DepartmentID.Substring(0, 4).Equals("1300"))
        {

            //总队司政后防
            if (user.DepartmentID.Substring(5, 1) == "1")
            {
                ReturnPage = "Home.aspx";
            }
            else if (user.DepartmentID.Substring(5, 1) == "4")
            {
                ReturnPage = "Home6.aspx";
            }
            else if (user.DepartmentID.Substring(5, 1) == "2")
            {
                ReturnPage = "Home7.aspx";
            }
            else if (user.DepartmentID.Substring(5, 1) == "3")
            {
                ReturnPage = "Home8.aspx";
            }
            else
                if (user.DepartmentID.Substring(5, 1) == "5")
                {
                    ReturnPage = "HomeXCZX.aspx";
                }
                else
                {
                    ReturnPage = "Home4.aspx";
                }
        }
        else if (user.DepartmentID.Substring(0, 4) != "1300" && user.DepartmentID.Substring(4, 1) == "0")
        {
            //机关党委
            if (user.DepartmentID.Substring(5, 1) == "0")
            {
                ReturnPage = "HomeZhidu/Home.aspx";
            }
            else
                //司令处
                if (user.DepartmentID.Substring(5, 1) == "1")
                {
                    ReturnPage = "HomeZhidu/Slb.aspx";
                }//政治处
                else if (user.DepartmentID.Substring(5, 1) == "2")
                {
                    ReturnPage = "HomeZhidu/zzb.aspx";
                }
                //后勤处
                else if (user.DepartmentID.Substring(5, 1) == "3")
                {
                    ReturnPage = "HomeZhidu/hqb.aspx";
                }//防火处
                else if (user.DepartmentID.Substring(5, 1) == "4")
                {
                    ReturnPage = "HomeZhidu/fhb.aspx";

                }//宣传科
                else if (user.DepartmentID.Substring(5, 1) == "5")
                {
                    ReturnPage = "HomeZhidu/xck.aspx";
                }
        }
        else if (user.DepartmentID == "1314100")
        {
            ReturnPage = "HomeZhidu/fhb.aspx";
        }
        else
            //中队
            if (user.DepartmentID.Substring(4, 1).Equals("3"))
                ReturnPage = "Homezhongdu.aspx";
            else
                //大队
                if (user.DepartmentID.Substring(4, 1).Equals("2"))
                    ReturnPage = "DaDuHome.aspx";
                else
                    if (user.DepartmentID.Substring(5, 1) == "1")
                    {

                        ReturnPage = "Home3.aspx";
                    }
                    else
                    {
                        ReturnPage = "Home4.aspx";
                    }


        return ReturnPage;
    }
    protected void ButtonLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("UserLogin.aspx");
    }
}
